#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
检查Python环境中的依赖版本信息
用于诊断numpy/xgboost兼容性问题
"""

import sys

def check_package_version(package_name):
    """尝试导入包并返回版本信息"""
    try:
        # 动态导入包
        module = __import__(package_name)
        # 获取版本信息
        version = getattr(module, '__version__', '未知版本')
        return f"✓ {package_name}: {version}"
    except ImportError as e:
        return f"✗ {package_name}: 未安装 ({str(e)})"
    except Exception as e:
        return f"! {package_name}: 导入出错 ({str(e)})"

# 检查Python版本
print(f"Python版本: {sys.version}")
print("-" * 50)

# 检查关键依赖版本
packages = [
    'numpy',
    'xgboost',
    'pandas',
    'scikit-learn',
    'flask',
    'flask_sqlalchemy',
    'celery',
    'redis'
]

for package in packages:
    print(check_package_version(package))

print("-" * 50)
print("建议操作:")
print("1. 如果numpy和xgboost版本不兼容，尝试:")
print("   pip install numpy==1.24.4 xgboost==2.0.0")
print("2. 或使用conda安装:")
print("   conda install numpy=1.24.4 xgboost=2.0.0")